package com.pp.arithmeticcommon.utils.sort;

import lombok.AccessLevel;
import lombok.NoArgsConstructor;

/**
 * 选择排序
 */
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class SelectionSort {

    public static void selectionSort(int[] array) {
        for (int i = 0; i < array.length - 1; i++) {
            int minIndex = i;
            for (int j = i + 1; j < array.length - 1; j++) {
                minIndex = array[minIndex] < array[j] ? minIndex : j;
            }

            int temp = array[i];
            array[i] = array[minIndex];
            array[minIndex] = temp;
        }
    }

}
